def f(r):
    c = 0
    for i in range(2, r):
        if r % i == 0:
            c += 1
    if c == 0:
        return True
    else:
        return False

s = input().split()
words = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
wrong = False
if s[0] == 'zero':
    wrong = True
if s[0] not in words or s[1] not in words or s[2] not in words:
    wrong = True
if len(s) != 3:
    wrong = True
if wrong:
    print('Wrong input')
else:
    aaa = words.index(s[0])
    bbb = words.index(s[1])
    ccc = words.index(s[2])
    t = aaa * 100 + bbb * 10 + ccc
    
b = t
bb = 0
d = t
dd = 0
if f(t) == True:
    print(t)
else:
    while f(b) == False: 
        b -= 1
        if f(b) == True:
            bb = b
            break
    while f(d) == False:
        d += 1
        if f(d) == True:
            dd = d
            break
    if dd - t < t - bb:
        print(dd)
    else:
        print(bb)
    
        
    
